package top.zy.boot.async.service.impl;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import top.zy.boot.async.service.AsyncService;

import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

/**
 * @author ZackYoung
 * @version 1.0
 * @date 2021/12/18
 */
@Service
public class AsyncServiceImpl implements AsyncService {
    @Override
    @Async
    public <T> CompletableFuture<T> asyncResult(Supplier<T> supplier) {
        return CompletableFuture.completedFuture(supplier.get());
    }

    @Async
    @Override
    public void asyncResult(Runnable runnable) {
        runnable.run();
    }
}
